/*******************************************************************************
 * Copyright (c) 2012 Clever Devices.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 * 	Clever Devices Interns - 
 * 	Alex Frankel, Andria Young, Kevin Thomas, Nicholas Culpepper, Taner Oztimurlenk, Thomas Volberg
 ******************************************************************************/
package com.framework.customerservice;

import java.util.ArrayList;

import com.framework.cleverstop_tentative.R;
import com.framework.menu.MenuAdapter;
import com.framework.menu.MenuItem;
import com.slidingmenu.lib.SlidingMenu;
import com.slidingmenu.lib.app.SlidingActivity;

import android.os.Bundle;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * This was simply the Lost Report Empty page
 * This was utilized for the actual form which was brought up without any information filled.
 * This was where you ended up when you selected "no" to using your most recent trip, 
 * from the lost and found page.
 * 
 * @author NCulpepper
 *
 */

public class LostReportEmpty extends SlidingActivity implements
		OnItemClickListener {

	TextView display, DTReported, DTLost, BusID, RouteID, DriverName,
			LostWhere, DescribeLost;
	Button submit;
	EditText DateReported, TimeReported, DateLost, TimeLost, Vehicle, Route,
			Driver, Where, Description;
	String sDateReported, sTimeReported, sDateLost, sTimeLost, sVehicle,
			sRoute, sDriver, sWhere, sDescription;
	NotificationManager nmLost;
	static final int uniqueLostID = 7734;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_lostreportempty);
	    nmLost = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        nmLost.cancel(uniqueLostID);
		setSlidingMenu();

		//display = (TextView) findViewById(R.id.tvLostReportEmpty);
		DTReported = (TextView) findViewById(R.id.tvDTReported);
		DateReported = (EditText) findViewById(R.id.etDateReported);
		TimeReported = (EditText) findViewById(R.id.etTimeReported);
		DTLost = (TextView) findViewById(R.id.tvDTLost);
		DateLost = (EditText) findViewById(R.id.etDateLost);
		TimeLost = (EditText) findViewById(R.id.etTimeLost);
		BusID = (TextView) findViewById(R.id.tvVehicleID);
		Vehicle = (EditText) findViewById(R.id.etVehicleID);
		RouteID = (TextView) findViewById(R.id.tvRoute);
		Route = (EditText) findViewById(R.id.etRoute);
		DriverName = (TextView) findViewById(R.id.tvDriver);
		Driver = (EditText) findViewById(R.id.etDriver);
		LostWhere = (TextView) findViewById(R.id.tvLostWhere);
		Where = (EditText) findViewById(R.id.etLostWhere);
		DescribeLost = (TextView) findViewById(R.id.tvDescription);
		Description = (EditText) findViewById(R.id.etDescription);
		submit = (Button) findViewById(R.id.bLostSubmit);
		
		Drawable d = this.getResources().getDrawable(R.drawable.layout_background);
		getActionBar().setBackgroundDrawable(d);
		getActionBar().setHomeButtonEnabled(true);

		submit.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				try {
					Class lostEmptyClass = Class
							.forName("com.framework.cleverstop_tentative.MainMenu");
					Intent lostEmptyIntent = new Intent(LostReportEmpty.this,
							lostEmptyClass);
					startActivity(lostEmptyIntent);
				} catch (ClassNotFoundException e) {
					e.printStackTrace();
				}
				finally{
//					When the submit button was selected this "toast" (below) was formatted to
//					pop up.  
//					Ideally, this toast would only occur after the form had been successfully confirmed
//					on the dispatcher/TA side of the communication.
					LayoutInflater inflater = getLayoutInflater();
					View layout = inflater.inflate(R.layout.customer_lost_notification, (ViewGroup) findViewById(R.id.toast_layout_root));
					ImageView image = (ImageView) layout.findViewById(R.id.ivLostNotif);
					image.setImageResource(R.drawable.ic_launcher);
					TextView text = (TextView) layout.findViewById(R.id.tvLostNotif);
					text.setText("Lost and Found Report Submitted!");
					Context contextLost = getApplicationContext();
					Toast toastLost = new Toast(getApplicationContext());
					toastLost.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
					toastLost.setDuration(Toast.LENGTH_LONG);
					toastLost.setView(layout);
					toastLost.show();
				}
			}
		});
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int index, long id) {
		// TODO Auto-generated method stub
		switch (index) {

		// this is where each intent will be started for all of your
		// respective sections. Look to the "BUSTIME" case as a model
		case REWARDS:
			Intent Rewards = new Intent("com.framework.rewards.REWARDS");
			startActivity(Rewards);
			break;
		case BOARDS:
			Intent Customer = new Intent(
					"com.framework.customerservice.CUSTOMER");
			startActivity(Customer);
			break;
		case FARES:
			Intent Fares = new Intent(
					"com.framework.cleverstop_tentative.FARESMAINACTIVITY");
			startActivity(Fares);
			break;
		case BUSTIME:
			Intent BusTime = new Intent(
					"com.framework.cleverstop_tentative.BUSTIMEMAINACTIVITY");
			startActivity(BusTime);
			break;
		}
	}

	ListView mainList;
	MenuAdapter listData;
	ListAdapter realListData;
	Button test;

	public final int REWARDS = 0;
	public final int BOARDS = 1;
	public final int FARES = 2;
	public final int BUSTIME = 3;

	/**
	 * Sets up properties for the sliding menu this will keep properties
	 * consistent across all activities
	 */
	public void setSlidingMenu() {
		// sets view that slides out from left, this will be standard across all
		// menus
		// allowing for quick and intuitive navigation
		setBehindContentView(R.layout.persistent_menu_list);

		MenuItem[] menuItems = {
				new MenuItem("Rewards", R.drawable.rewaredsicon, "1"),
				new MenuItem("Boards", R.drawable.boardsicon, ""),
				new MenuItem("Fares", R.drawable.faresicon, ""),
				new MenuItem("BusTime", R.drawable.bustimeicon, ""),
				new MenuItem("Settings", R.drawable.settinsicon, "") };

		ArrayList<MenuItem> items = new ArrayList<MenuItem>();
		for (int i = 0; i < menuItems.length; i++)
			items.add(menuItems[i]);

		listData = new MenuAdapter(this, R.layout.listview_item_row, items);

		mainList = (ListView) findViewById(R.id.menuList);

		// dynamically add items to listView
		// did below as a test, but can easily add items based on the section of
		// app you are in
		// listData.insert("BusTime", list.size());

		mainList.setAdapter(listData);
		mainList.setOnItemClickListener(this);

		getSlidingMenu().setBehindOffsetRes(R.dimen.DistanceFromSide);
		getSlidingMenu().setBehindScrollScale(0.5f);
		getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
		getSlidingMenu().setActivated(true);

	}
}
